package com.nd.qa.shareplate.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.nd.qa.shareplate.common.SessionUserInfo;
import com.nd.qa.shareplate.common.SysConstant;
import com.nd.qa.shareplate.model.Module;
import com.nd.qa.shareplate.model.OperatorLog;
import com.nd.qa.shareplate.model.PageElement;
import com.nd.qa.shareplate.model.SharePage;
import com.nd.qa.shareplate.service.ModuleService;
import com.nd.qa.shareplate.service.OperatorLogService;
import com.nd.qa.shareplate.service.PageElementService;
import com.nd.qa.shareplate.service.PageService;
import com.nd.qa.shareplate.util.FormatTimeUtil;
import com.nd.qa.shareplate.util.JsonUtil;

/**
 * <p>脚本页面控制类</p>
 * @author huangjian
 * @createDate 2015-09-20 下午 16:36:21
 * @version V1.0
 */
@Controller
@RequestMapping("/page/*")
public class PageController {

	Logger logger = LoggerFactory.getLogger(PageController.class);
	
	@Autowired
	@Qualifier("com.nd.qa.shareplate.service.ModuleService")
	private ModuleService moduleService;
	
	@Autowired
	@Qualifier("com.nd.qa.shareplate.service.PageService")
	private PageService pageService;
	
	@Autowired
	@Qualifier("com.nd.qa.shareplate.service.PageElementService")
	private PageElementService elementService;
	
	@Autowired
	@Qualifier("com.nd.qa.shareplate.service.OperatorLogService")
	private OperatorLogService operatorLogService;
	/**
	 * 新增页面元素
	 * <p>实现功能逻辑:1.复制所以记录，2.修改复制记录的目标元素id。3.修改复制记录的前置元素</p>
	 * @param request
	 * @param response
	 * @param session
	 * @param params
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping("/insertPageInfo")
	public void insertPageInfo(HttpServletRequest request,HttpServletResponse response,HttpSession session,@RequestBody String params){
		
		SessionUserInfo sessionUserInfo = (SessionUserInfo) session.getAttribute(SysConstant.SESSION_KEY_LOGIN_USER);
		HashMap<String, Object> resultMap = new HashMap<String,Object>();
		if (sessionUserInfo==null) {
			resultMap.put("code", "-2");
			resultMap.put("message", "您还未登录");
		}
		
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		
		HashMap<String, Object> inParam = JsonUtil.toObject(params, HashMap.class);
		//获取插入页面标识
		String pageFlag = String.valueOf(inParam.get("pageFlag"));
		//判断是否有复用
		String isTemplateFlag = String.valueOf(inParam.get("isTemplateFlag"));//用isTemplateFlag的值来判断是否复用模板,2:复用模板;0:正常逻辑新增页面
		String isSwitchPage = String.valueOf(inParam.get("isSwitchPage"));
		Integer focusTypeId = null;
		String focusTypeName = null;
		if (inParam.get("focusTypeId")!=null&&String.valueOf(inParam.get("focusTypeId")).length()>0) {
			focusTypeId = Integer.valueOf(String.valueOf(inParam.get("focusTypeId")));//聚焦操作
			focusTypeName = String.valueOf(inParam.get("focusTypeName"));//聚焦操作名称
		}
		Integer moduleId = Integer.valueOf(String.valueOf(inParam.get("moduleId")));//当前操作的模块ID
		String pageName = String.valueOf(inParam.get("pageName"));//输入的新增页面名称或者复用页面名称
		String pageId = String.valueOf(inParam.get("pageId"));//pageId为当前操作页面的ID
		String elementExpectName = String.valueOf(inParam.get("elementExpectName"));//期待结果元素类型
		String elementExpectType = String.valueOf(inParam.get("elementExpectType"));//期待结果元素类型
		String elementExpectContent = String.valueOf(inParam.get("elementExpectContent"));//期待结果元素类型，内容
		String elementExpectOrder = String.valueOf(inParam.get("elementExpectOrder"));
		String elementWaitTime = String.valueOf(inParam.get("elementWaitTime"));
		if (elementExpectOrder==null||"".equals(elementExpectOrder)) {
			elementExpectOrder = "0";
		}
		if (elementWaitTime==null||"".equals(elementWaitTime)) {
			elementWaitTime = "0";
		}
		//是否需要切换iFrame
		String isIframeFlag = String.valueOf(inParam.get("isIFrameFlag"));
		String overIFrameFlag = String.valueOf(inParam.get("overIFrameFlag"));//是否结束iframe
		String iFrameElementType = "";
		String iFrameElementContent = "";
		if ("2".equals(isIframeFlag)) {
			iFrameElementType = String.valueOf(inParam.get("iFrameElementType"));
			iFrameElementContent = String.valueOf(inParam.get("iFrameElementContent"));
		}
		String elementExpectResult = String.valueOf(inParam.get("elementExpectResult"));
		String elementOperateDesc = String.valueOf(inParam.get("elementOperateDesc"));
		String templateModuleName = String.valueOf(inParam.get("templateModuleName"));//复用模板的模块名称
		String templatePageDepth = String.valueOf(inParam.get("templatePageDepth"));//复用模板页面所处的层级
		String dragPageId = String.valueOf(inParam.get("dragPageId"));
		String nativeParentPageId = String.valueOf(inParam.get("nativeParentPageId"));
	    try {
	    	if (isTemplateFlag!=null&&!"null".equals(isTemplateFlag)) {
	    		if ("2".equals(isTemplateFlag)) {
					//0.查询当前操作页面的信息
	    			SharePage currentPage = null;
					Integer depth = 0;//当前页面的深度
					Integer parentId = 0;
					if (pageId!=null&&!"".equals(pageId)&&!"0".equals(pageId)) {
						currentPage = pageService.queryPageById(Integer.valueOf(pageId));//若当前页面并非起始页面，那么需要查询当前操作页面的相关信息
						depth = currentPage.getPageDepth()+1;//获取当前操作页面的深度,若当前操作页面不是模块节点，那么新增页面的深度需要在当前操作页面基础上加 1
					}
					//1.查询模块所属的项目
					Module module = moduleService.queryModuleById(moduleId);
					//2.查询该项目下名称为templateModuleName的模块
					Module paramModule = new Module();
					paramModule.setProjectId(module.getProjectId());
					paramModule.setModuleName(templateModuleName);
					Module module2 = moduleService.queryModuleByParams(paramModule);
					Integer templateModuleId = module2.getModuleId();//拷贝模板的模块ID
					//判断拷贝的页面是否就是自己模块下的页面
					if (templateModuleId!=moduleId) {
						//3.通过模块ID和页面名称查找模板页面
						SharePage pmPage = new SharePage();
						pmPage.setModuleId(templateModuleId);
						pmPage.setPageName(pageName);
						if (templatePageDepth!=null&&!"".equals(templatePageDepth)) {
							pmPage.setPageDepth(Integer.valueOf(templatePageDepth));
						}
						SharePage templatePage = pageService.queryTemplatePage(pmPage);//查询模板页面信息
						Integer templatePageId = templatePage.getPageId();//要拷贝的pageid
						//赋值模板页面，并在新模块中新增页面
						SharePage page = new SharePage();
						if (depth!=0) {
							//depth = depth +1;//若当前操作页面不是起始页面，那么新增页面的深度需要在当前操作页面基础上加 1
							parentId = Integer.valueOf(pageId);//若当前操作页面不是起始页面，那么当前操作页面的Id即为新增页面的父Id
						}
						//处理新增页面中的目标元素Id，若模板页面不是起始页面（if）
						//加上当前页面pageId的判断，进去if中的逻辑还必须满足当前操作的页面并非起始页，否则无需对当前操作页面增加目标元素信息
						if (templatePage.getElementTargetId()!=null&&!"null".equals(templatePage.getElementTargetId())&&templatePage.getElementTargetId()!=0&&pageId!=null&&!"".equals(pageId)&&!"0".equals(pageId)) {
							//通过模板子页面中的ElementTargetId来查找其在元素表的详细信息
							PageElement targetParam = new PageElement();
							targetParam.setElementId(templatePage.getElementTargetId());
							PageElement childPageElement = elementService.queryElementInfoByElemId(targetParam);//页面目标元素的详细信息
							//在当前页面的元素信息中添加该模板目标元素信息，除页面ID之外的信息
							PageElement currentPageEleParam = new PageElement();
							Integer currentElementId = elementService.quertElmSeqByName("element_seq");
							currentPageEleParam.setDragCount(childPageElement.getDragCount());
							currentPageEleParam.setElementActionId(childPageElement.getElementActionId());
							currentPageEleParam.setElementActionName(childPageElement.getElementActionName());
							currentPageEleParam.setElementContent(childPageElement.getElementContent());
							currentPageEleParam.setElementId(currentElementId);
							currentPageEleParam.setElementName(childPageElement.getElementName());
							currentPageEleParam.setElementOperationOrder(childPageElement.getElementOperationOrder());
							currentPageEleParam.setElementOrder(childPageElement.getElementOrder());
							if (childPageElement.getElementPreciousId()==0) {
								currentPageEleParam.setElementPreciousId(0);
							}else{
								//查询当前操作页面中元素id的最大值
								Integer maxElementId = elementService.queryMaxElementId(Integer.valueOf(pageId));
								currentPageEleParam.setElementPreciousId(maxElementId);//childPageElement.getElementPrecious() 若前置元素不为0，那么复制当前操作页面中，id值为最大的元素当做这个目标元素记录的前置元素
							}
							currentPageEleParam.setElementText(childPageElement.getElementText());
							currentPageEleParam.setElementTypeFlag(childPageElement.getElementTypeFlag());
							currentPageEleParam.setElementTypeId(childPageElement.getElementTypeId());
							currentPageEleParam.setElementTypeName(childPageElement.getElementTypeName());
							currentPageEleParam.setPageId(Integer.valueOf(pageId));
							currentPageEleParam.setStatus("A");
							page.setElementTargetId(currentElementId);//将在当前页面中添加的目标元素信息中的ElementId作为新增页面中的目标元素ID(ElementTargetId)
							elementService.insertElememt(currentPageEleParam);
						}else{
							page.setElementTargetId(0);
						}
						//查询新增页面的pageid
						Integer newPageId = pageService.queryPageSeqByName("page_seq");
						page.setPageId(newPageId);
						page.setCreateTime(templatePage.getCreateTime());
						page.setPageDepth(depth);
						page.setPageStatus(templatePage.getPageStatus());
						page.setModuleId(moduleId);
						page.setPageName(pageName);
						page.setParentPageId(parentId);
						page.setStatus("A");
						pageService.insertPageInfo(page);
						//4.查询该模板页面下的元素信息
						List<PageElement> elementLists = elementService.queryElementForPageId(templatePageId);
						//5.将该模板下的元素拷贝一份到新增页面下
						//定义原元素信息和新元素信息
						List<HashMap<Integer, Object>> oldList = new ArrayList<HashMap<Integer,Object>>();
						List<HashMap<Integer, Object>> newList = new ArrayList<HashMap<Integer,Object>>();
						
						for (int i = 0; i < elementLists.size(); i++) {
							PageElement pageElement = new PageElement();
							//获取新增元素的ID----查询元素列表序列
							//定义两个存储键对的Map oldMap:key-模板元素id,value-模板元素前置id   newMap:key-模板元素id,value-新生成的元素id
							HashMap<Integer, Object> oldMap = new HashMap<Integer,Object>();
							HashMap<Integer, Object> newMap = new HashMap<Integer,Object>();
							 Integer elementSeq = elementService.quertElmSeqByName("element_seq");
							 pageElement.setPageId(newPageId);
							 pageElement.setElementId(elementSeq);
							 pageElement.setDragCount(elementLists.get(i).getDragCount());
							 pageElement.setElementActionId(elementLists.get(i).getElementActionId());
							 pageElement.setElementActionName(elementLists.get(i).getElementActionName());
							 pageElement.setElementContent(elementLists.get(i).getElementContent());
							 pageElement.setElementName(elementLists.get(i).getElementName());
							 pageElement.setElementOperationOrder(elementLists.get(i).getElementOperationOrder());
							 pageElement.setElementOrder(elementLists.get(i).getElementOrder());
							 pageElement.setElementPreciousId(elementLists.get(i).getElementPreciousId());
							 pageElement.setElementText(elementLists.get(i).getElementText());
							 pageElement.setElementTypeFlag(elementLists.get(i).getElementTypeFlag());
							 pageElement.setElementTypeId(elementLists.get(i).getElementTypeId());
							 pageElement.setElementTypeName(elementLists.get(i).getElementTypeName());
							 pageElement.setElementOperateDesc(elementLists.get(i).getElementOperateDesc());
							 pageElement.setElementExpectName(elementLists.get(i).getElementExpectName());
							 pageElement.setElementExpectType(elementLists.get(i).getElementExpectType());
							 pageElement.setElementExpectContent(elementLists.get(i).getElementExpectContent());
							 pageElement.setElementExpectOrder(elementLists.get(i).getElementExpectOrder());
							 pageElement.setElementExpectResult(elementLists.get(i).getElementExpectResult());
							 pageElement.setElementForPage(elementLists.get(i).getElementForPage());
							 pageElement.setStatus("A");
							 //元素存储键对值
							 oldMap.put(elementLists.get(i).getElementId(), elementLists.get(i).getElementPreciousId());
							 oldList.add(oldMap);
							 newMap.put(elementLists.get(i).getElementId(), elementSeq);
							 newList.add(newMap);
							 //copy元素信息
							 elementService.insertElememt(pageElement);
						}
						for (HashMap<Integer, Object> hashMap2 : newList) {
							if (hashMap2.entrySet().iterator().hasNext()) {
								Entry entry2 = (Entry)hashMap2.entrySet().iterator().next();
								for (HashMap<Integer, Object> hashMap1 : oldList) {
									if (hashMap1.entrySet().iterator().hasNext()) {
										Entry entry1 = (Entry)hashMap1.entrySet().iterator().next();
										if (entry2.getKey()==entry1.getKey()) {
											//获取map的value值
											System.out.println(entry1.getKey()+","+entry1.getValue());
											if ("0".equals(String.valueOf(entry1.getValue()))) {
												//获取value2
												System.out.println("value2="+entry2.getValue());
												//修改value2的前置元素值为0
												//TODO
												PageElement el = new PageElement();
												el.setElementId(Integer.valueOf(String.valueOf(entry2.getValue())));
												el.setElementPreciousId(0);
												elementService.updateCopyElements(el);
											}else{
												//获取value2的值
											  String value2 = String.valueOf(entry2.getValue());
											  String value1 = String.valueOf(entry1.getValue());
											  //通过value1的值到map2中值遍历寻找key2==value1的键值对
											  for(HashMap<Integer, Object> hashMap22 : newList){
												  if (hashMap22.entrySet().iterator().hasNext()) {
													  Entry entry22 = (Entry)hashMap22.entrySet().iterator().next();
													  if (value1.equals(String.valueOf(entry22.getKey()))) {
															//获取key22所对应的value22
															String value22 = String.valueOf(entry22.getValue());
															System.out.println("value22="+value22);
															//将value2作为元素的ID,修改该记录的前置元素为value22
															PageElement el = new PageElement();
															el.setElementId(Integer.valueOf(value2));
															el.setElementPreciousId(Integer.valueOf(value22));
															elementService.updateCopyElements(el);
															break;
													  }
												}
										}
									}
									break;
								}
							}
						}
					}
				}
						/*//处理新生成元素的前置元素逻辑
						Iterator it1 = oldMap.entrySet().iterator();
						Iterator it2 = newMap.entrySet().iterator();
						Iterator it22 = newMap.entrySet().iterator();
						while(it2.hasNext()){
							Entry entry2 = (Entry)it2.next();
							while (it1.hasNext()) {
								Entry entry1 = (Entry)it1.next();
								if (entry2.getKey()==entry1.getKey()) {
									//获取map的value值
									System.out.println(entry1.getKey()+","+entry1.getValue());
									if ("0".equals(String.valueOf(entry1.getValue()))) {
										//获取value2
										System.out.println("value2="+entry2.getValue());
										//修改value2的前置元素值为0
										//TODO
										PageElement el = new PageElement();
										el.setElementId(Integer.valueOf(String.valueOf(entry2.getValue())));
										el.setElementPreciousId(0);
										elementService.updateCopyElements(el);
									}else{
										//获取value2的值
									  String value2 = String.valueOf(entry2.getValue());
									  String value1 = String.valueOf(entry1.getValue());
									  //通过value1的值到map2中值遍历寻找key2==value1的键值对
									  while (it22.hasNext()) {
										  Entry entry22 = (Entry)it22.next();
										if (value1.equals(String.valueOf(entry22.getKey()))) {
											//获取key22所对应的value22
											String value22 = String.valueOf(entry22.getValue());
											System.out.println("value22="+value22);
											//将value2作为元素的ID,修改该记录的前置元素为value22
											PageElement el = new PageElement();
											el.setElementId(Integer.valueOf(value2));
											el.setElementPreciousId(Integer.valueOf(value22));
											elementService.updateCopyElements(el);
											break;
										}
									  }                  
									}
									break;
								}
							}
						}*/
						//6.查询模板page下是否存在子页面
						SharePage paramPage = new SharePage();
						paramPage.setPageId(newPageId);
						paramPage.setParentPageId(templatePageId);
						paramPage.setPageDepth(depth);
						paramPage.setModuleId(moduleId);
						callBackCopyPage(paramPage);
						resultMap.put("code", "0");
						resultMap.put("message", "添加页面成功");
					}else{
						resultMap.put("code", "-1");
						resultMap.put("message", "不能在本模块拷贝页面模板！");
					}
				}else{
					//正常逻辑新增页面
					SharePage page = new SharePage();
					PageElement pageElement = new PageElement();
					Integer depth = 0;
					Integer pageStatus = 0;
					Integer parentId =  0;
					Integer elementSeq = 0;
					try {
						//判断是否是根页面
						if (!"".equals(pageId)&&pageId!=null&&!"null".equals(pageId)&&!"0".equals(pageId)) {
							//处理page信息
							//非根页面，则查询该页面信息
							page.setModuleId(moduleId);
							page.setPageId(Integer.valueOf(pageId));
							HashMap<String, Object> pageMap = pageService.queryPageInfo(page);
							//组织树深度
							depth = Integer.valueOf(String.valueOf(pageMap.get("page_depth")));
							depth = depth+1;//深度增加一级
							parentId = Integer.valueOf(pageId);
							//处理page中的元素信息（ci_page_element）
							String elementContent = String.valueOf(inParam.get("elementContent"));
							if (elementContent!=null) {
								elementContent = elementContent.replaceAll("\"","\'");
							}
							pageElement.setPageId(Integer.valueOf(pageId));
							pageElement.setElementTypeId(Integer.valueOf(String.valueOf(inParam.get("elementTypeId"))));
							pageElement.setElementTypeName(String.valueOf(inParam.get("elementTypeName")));
							pageElement.setElementContent(elementContent);
							if (inParam.get("elementOrder")!=null&&!"".equals(inParam.get("elementOrder"))) {
								pageElement.setElementOrder(Integer.valueOf(String.valueOf(inParam.get("elementOrder"))));
							}else {
								pageElement.setElementOrder(0);
							}
							if (inParam.get("elementWaitTime")!=null&&!"".equals(inParam.get("elementWaitTime"))) {
								pageElement.setElementWaitTime(Long.valueOf(String.valueOf(inParam.get("elementWaitTime"))));
							}else {
								pageElement.setElementWaitTime(0);
							}
							pageElement.setElementActionId(Integer.valueOf(String.valueOf(inParam.get("elementActionId"))));
							pageElement.setElementActionName(String.valueOf(inParam.get("elementActionName")));
							if (inParam.get("elementPrecious")!=null&&!"".equals(inParam.get("elementPrecious"))) {
								pageElement.setElementPreciousId(Integer.valueOf(String.valueOf(inParam.get("elementPrecious"))));
							}else {
								pageElement.setElementPreciousId(0);
							}
							pageElement.setIsIframeFlag(isIframeFlag);
							pageElement.setOverIframeFlag(overIFrameFlag);//是否结束iframe
							pageElement.setIframeElementType(iFrameElementType);
							pageElement.setIframeElementContent(iFrameElementContent);
							
							pageElement.setElementTextFlag(String.valueOf(inParam.get("elementTextFlag")));
							pageElement.setElementText(String.valueOf(inParam.get("elementText")));//输入内容
							pageElement.setElementExpectName(elementExpectName);//操作元素信息描述
							pageElement.setElementExpectType(elementExpectType);//操作元素校验类型
							pageElement.setElementExpectContent(elementExpectContent);//操作元素,内容
							pageElement.setElementExpectOrder(Integer.valueOf(elementExpectOrder));//操作元素信息描述
							pageElement.setElementExpectResult(elementExpectResult);
							pageElement.setElementOperateDesc(elementOperateDesc);//操作元素信息描述
							pageElement.setIsSwitchPage(isSwitchPage);//判断是否需要切换页面
							pageElement.setFocusTypeId(focusTypeId);//聚焦操作
							pageElement.setFocusTypeName(focusTypeName);//聚焦操作名称
							//拖曳次数
							if (inParam.get("dragCount")!=null&&!"".equals(inParam.get("dragCount"))) {
								pageElement.setDragCount(Integer.valueOf(String.valueOf(inParam.get("dragCount"))));
							}
							pageElement.setStatus("A");
							//查询元素列表序列
							 elementSeq = elementService.quertElmSeqByName("element_seq");
							 pageElement.setElementId(elementSeq);
							 pageElement.setElementForPage("Y");
						}
						SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						String createTime = simpleDateFormat.format(new Date());
						Integer createPageId = 0;//新页面id
						//查询新增页面的pageid
						if (dragPageId!=null&&!"".equals(dragPageId)&&!"null".equals(dragPageId)&&dragPageId.length()!=0) {
							page.setPageId(Integer.valueOf(dragPageId));
							page.setPageDepth(depth);
							page.setParentPageId(Integer.valueOf(pageId));
							page.setElementTargetId(elementSeq);
							pageService.updatePage(page);
							//修改被拖拽页面下，所有子页面的层级关系
							//1.查询被拖拽页面下子页面
							updateDragedPageToChild(Integer.valueOf(dragPageId),moduleId,depth);
						}else{
							createPageId = pageService.queryPageSeqByName("page_seq");
							page.setPageId(createPageId);
							page.setCreateTime(createTime);
							page.setPageDepth(depth);
							page.setPageStatus(pageStatus);
							page.setModuleId(moduleId);
							page.setPageName(pageName);
							page.setParentPageId(parentId);
							page.setStatus("A");
							page.setElementTargetId(elementSeq);
							//插入页面操作
							if ("insert".equals(pageFlag)) {
								//查询当前页面的id
								List<SharePage> childPages = pageService.queryChildPages(page);
								//修改子页面信息 parent_page_id 和 page_depth
								for (SharePage cpage : childPages) {
									SharePage page2 = new SharePage();
									page2.setPageId(cpage.getPageId());
									page2.setParentPageId(createPageId);
									page2.setModuleId(cpage.getModuleId());
									page2.setPageDepth(cpage.getPageDepth()+1);
									pageService.updateChildPage(page2);
								}
							}
							//添加新页面
							pageService.insertPageInfo(page);
							//插入页面操作
							if ("insert".equals(pageFlag)) {
								//修改父节点的元素依赖关系
								//List<SharePage> parentPage = pageService.queryPageById(Integer.valueOf(pageId));
								SharePage sPage = new SharePage();
								sPage.setModuleId(moduleId);
								sPage.setParentPageId(createPageId);
								List<SharePage> parentPages = pageService.queryPagesById(sPage);
								for (SharePage pPage : parentPages) {
									HashMap<String, Object> pElement = new HashMap<String,Object>();
									pElement.put("elementId", pPage.getElementTargetId());
									//pElement.put("newElementId", page.getElementTargetId());
									pElement.put("pageId", createPageId);
									elementService.updateElementById(pElement);
								}
							}
							//操作日志记录
							insertOperatorLog(sessionUserInfo.getUserId(),SysConstant.OPERATOR_ACTION_ADD_LOG,SysConstant.OPERATOR_TYPE_PAGE_LOG,createPageId,-1);
						}
						
						//增加页面元素
						if (pageElement!=null&&!"".equals(pageElement)&&pageElement.getPageId()!=null) {
							elementService.insertElememt(pageElement);
							//操作日志记录
							insertOperatorLog(sessionUserInfo.getUserId(),SysConstant.OPERATOR_ACTION_ADD_LOG,SysConstant.OPERATOR_TYPE_ELEMENT_LOG,-1,pageElement.getElementId());
						}
					} catch (Exception e) {
						logger.error("添加页面异常："+e.toString());
						e.printStackTrace();
					}
					resultMap.put("code", "0");
					resultMap.put("message", "添加页面成功");
				}
				//response.getWriter().print(JsonUtil.toString(resultMap));
			}
		} catch (IOException e) {
			logger.error("IOException:"+e);
			resultMap.put("code", "-1");
			resultMap.put("message", "新增页面异常");
			e.printStackTrace();
		}catch (NumberFormatException e) {
			logger.error("NumberFormatException:"+e);
			resultMap.put("code", "-1");
			resultMap.put("message", "新增页面异常");
			e.printStackTrace();
		} catch (Exception e) {
			logger.error("Exception:"+e);
			resultMap.put("code", "-1");
			resultMap.put("message", "新增页面异常");
			e.printStackTrace();
		}finally{
			try {
				response.getWriter().print(JsonUtil.toString(resultMap));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	/**
	 * 操作日志类
	 * @param userId
	 * @param operatorAction
	 * @param operatorType
	 */
	public void insertOperatorLog(String userId,String operatorAction,String operatorType,Integer pageId,Integer elementId){
		try {
			OperatorLog operatorLog = new OperatorLog();
			operatorLog.setUserId(userId);
			operatorLog.setOperatorAction(operatorAction);
			operatorLog.setOperatorType(operatorType);
			operatorLog.setPageId(pageId);
			operatorLog.setElementId(elementId);
			operatorLog.setCreateTime(FormatTimeUtil.dateToStrLong(new Date()));
			operatorLog.setStatus("A");
			operatorLogService.insertOperatorLog(operatorLog);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 修改被拖拽页面下子页面的层级关系
	 * @param dragPageId
	 * @return
	 */
	public boolean updateDragedPageToChild(Integer dragPageId,Integer moduleId,Integer pageDepth){
		try {
			SharePage pPage = new SharePage();
			pPage.setParentPageId(Integer.valueOf(dragPageId));
			pPage.setModuleId(moduleId);
			List<SharePage> listPages = pageService.queryChildPageForId(pPage);
			for (int i = 0; i < listPages.size(); i++) {
				SharePage childPage = listPages.get(i);
				SharePage cPage = new SharePage();
				cPage.setPageId(childPage.getPageId());
				cPage.setPageDepth(pageDepth+1);
				pageService.updateChildPage(cPage);
				updateDragedPageToChild(childPage.getPageId(),childPage.getModuleId(),pageDepth+1);
			}
		} catch (Exception e) {
			logger.debug("拖拽页面时修改子页面层级关系异常",e);//e.printStackTrace();
			return false;
		}
		return true;
	}
	/**
	 * 子页面深度拷贝回溯
	 * @param paramPage(parentId)
	 */
	@SuppressWarnings("rawtypes")
	public void callBackCopyPage(SharePage paramPage){
		
		try {
			List<SharePage> childPages = pageService.queryChildPages(paramPage);
			Integer depth = paramPage.getPageDepth()+1;
			for (int i = 0; i < childPages.size(); i++) {
				//将子页面复制一份
				SharePage page = childPages.get(i);//获取到的模板子页面
				SharePage inParam = new SharePage();//新增页面定义
				if (page.getElementTargetId()!=null&&!"null".equals(page.getElementTargetId())&&page.getElementTargetId()!=0) {
					//通过模板子页面中的ElementTargetId来查找其在元素表的详细信息
					PageElement targetParam = new PageElement();
					targetParam.setElementId(page.getElementTargetId());
					PageElement childPageElement = elementService.queryElementInfoByElemId(targetParam);
					//通过模板元素的信息，在新增页面的父页面元素中去查找该新增页面中的目标元素ID 
					PageElement paramElement = new PageElement();
					paramElement.setPageId(paramPage.getPageId());
					paramElement.setElementTypeId(paramElement.getElementTypeId());
					paramElement.setElementContent(childPageElement.getElementContent());
					paramElement.setElementOrder(childPageElement.getElementOrder());
					//paramElement.setElementPrecious(childPageElement.getElementPrecious());
					paramElement.setElementText(childPageElement.getElementText());
					paramElement.setElementForPage(childPageElement.getElementForPage());
					PageElement targetElement = elementService.queryTargetElement(paramElement);
					inParam.setElementTargetId(targetElement.getElementId());
				}else{
					inParam.setElementTargetId(0);
				}
				//查询新增页面的pageid
				Integer newPageId = pageService.queryPageSeqByName("page_seq");
				inParam.setPageId(newPageId);
				inParam.setCreateTime(page.getCreateTime());
				inParam.setPageDepth(depth);
				inParam.setPageStatus(page.getPageStatus());
				inParam.setModuleId(paramPage.getModuleId());
				inParam.setPageName(page.getPageName());
				inParam.setParentPageId(paramPage.getPageId());
				inParam.setStatus("A");
				pageService.insertPageInfo(inParam);
				//2.查询该模板页面下的元素信息
				List<PageElement> elementLists = elementService.queryElementForPageId(page.getPageId());
				//定义原元素信息和新元素信息
				List<HashMap<Integer, Object>> oldList = new ArrayList<HashMap<Integer,Object>>();
				List<HashMap<Integer, Object>> newList = new ArrayList<HashMap<Integer,Object>>();
				//3.将该模板下的元素拷贝一份到新增页面下
				for (int j = 0; j < elementLists.size(); j++) {
					PageElement pageElement = new PageElement();
					//获取新增元素的ID----查询元素列表序列
					//定义两个存储键对的Map oldMap:key-模板元素id,value-模板元素前置id   newMap:key-模板元素id,value-新生成的元素id
					 HashMap<Integer, Object> oldMap = new HashMap<Integer,Object>();
					 HashMap<Integer, Object> newMap = new HashMap<Integer,Object>();
					 Integer elementSeq = elementService.quertElmSeqByName("element_seq");
					 pageElement.setPageId(newPageId);
					 pageElement.setElementId(elementSeq);
					 pageElement.setDragCount(elementLists.get(j).getDragCount());
					 pageElement.setElementActionId(elementLists.get(j).getElementActionId());
					 pageElement.setElementActionName(elementLists.get(j).getElementActionName());
					 pageElement.setElementContent(elementLists.get(j).getElementContent());
					 pageElement.setElementName(elementLists.get(j).getElementName());
					 pageElement.setElementOperationOrder(elementLists.get(j).getElementOperationOrder());
					 pageElement.setElementOrder(elementLists.get(j).getElementOrder());
					 pageElement.setElementPreciousId(elementLists.get(j).getElementPreciousId());
					 pageElement.setElementText(elementLists.get(j).getElementText());
					 pageElement.setElementTypeFlag(elementLists.get(j).getElementTypeFlag());
					 pageElement.setElementTypeId(elementLists.get(j).getElementTypeId());
					 pageElement.setElementTypeName(elementLists.get(j).getElementTypeName());
					 pageElement.setElementOperateDesc(elementLists.get(j).getElementOperateDesc());
					 pageElement.setElementExpectName(elementLists.get(j).getElementExpectName());
					 pageElement.setElementExpectOrder(elementLists.get(j).getElementExpectOrder());
					 pageElement.setElementExpectResult(elementLists.get(j).getElementExpectResult());
					 pageElement.setElementForPage(elementLists.get(j).getElementForPage());
					 pageElement.setStatus("A");
					 //元素存储键对值
					 oldMap.put(elementLists.get(j).getElementId(), elementLists.get(j).getElementPreciousId());
					 oldList.add(oldMap);
					 newMap.put(elementLists.get(j).getElementId(), elementSeq);
					 newList.add(newMap);
					 //copy元素信息
					 elementService.insertElememt(pageElement);
				}
				for (HashMap<Integer, Object> hashMap2 : newList) {
					if (hashMap2.entrySet().iterator().hasNext()) {
						Entry entry2 = (Entry)hashMap2.entrySet().iterator().next();
						for (HashMap<Integer, Object> hashMap1 : oldList) {
							if (hashMap1.entrySet().iterator().hasNext()) {
								Entry entry1 = (Entry)hashMap1.entrySet().iterator().next();
								if (entry2.getKey()==entry1.getKey()) {
									//获取map的value值
									System.out.println(entry1.getKey()+","+entry1.getValue());
									if ("0".equals(String.valueOf(entry1.getValue()))) {
										//获取value2
										System.out.println("value2="+entry2.getValue());
										//修改value2的前置元素值为0
										//TODO
										PageElement el = new PageElement();
										el.setElementId(Integer.valueOf(String.valueOf(entry2.getValue())));
										el.setElementPreciousId(0);
										elementService.updateCopyElements(el);
									}else{
										//获取value2的值
									  String value2 = String.valueOf(entry2.getValue());
									  String value1 = String.valueOf(entry1.getValue());
									  //通过value1的值到map2中值遍历寻找key2==value1的键值对
									  for(HashMap<Integer, Object> hashMap22 : newList){
										  if (hashMap22.entrySet().iterator().hasNext()) {
											  Entry entry22 = (Entry)hashMap22.entrySet().iterator().next();
											  if (value1.equals(String.valueOf(entry22.getKey()))) {
													//获取key22所对应的value22
													String value22 = String.valueOf(entry22.getValue());
													System.out.println("value22="+value22);
													//将value2作为元素的ID,修改该记录的前置元素为value22
													PageElement el = new PageElement();
													el.setElementId(Integer.valueOf(value2));
													el.setElementPreciousId(Integer.valueOf(value22));
													elementService.updateCopyElements(el);
													break;
											  }
										}
								}
							}
							break;
						}
					}
				}
					}
				}
				//再次回调该方法
				SharePage callPage = new SharePage();
				callPage.setParentPageId(page.getPageId());
				callPage.setModuleId(paramPage.getModuleId());
				callPage.setPageDepth(depth);
				callPage.setPageId(newPageId);
				callBackCopyPage(callPage);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 修改页面名称
	 * @param request
	 * @param response
	 * @param session
	 * @param params
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/modifyPage")
	public void modifyPage(HttpServletRequest request,HttpServletResponse response,HttpSession session,@RequestBody String params){
		SessionUserInfo sessionUserInfo = (SessionUserInfo) session.getAttribute(SysConstant.SESSION_KEY_LOGIN_USER);
		HashMap<String, Object> resultMap = new HashMap<String,Object>();
		if (sessionUserInfo==null) {
			resultMap.put("code", "-2");
			resultMap.put("message", "您还未登录，请先登录...");
		}
		HashMap<String, Object> inParam = JsonUtil.toObject(params, HashMap.class);
		SharePage page = new SharePage();
		String pageId = String.valueOf(inParam.get("pageId"));
		String pageName = String.valueOf(inParam.get("pageName"));
		try {
			//修改页面
			page.setPageId(Integer.valueOf(pageId));
			page.setPageName(pageName);
			pageService.modifyPage(page);
			insertOperatorLog(sessionUserInfo.getUserId(),SysConstant.OPERATOR_ACTION_UPDATE_LOG, SysConstant.OPERATOR_TYPE_PAGE_LOG, Integer.valueOf(pageId), -1);
			//TODO 暂时无法修改，父界面的对应的元素信息，只能去父界面的元素信息列表界面去修改
			//查询该界面的父界面
			//Page pageInfo = pageService.queryPageById(Integer.valueOf(pageId));
			//通过父界面id，修改其元素信息
			resultMap.put("code", "0");
			resultMap.put("message", "添加页面成功");
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/html;charset=UTF-8");
		    response.getWriter().print(JsonUtil.toString(resultMap));
		} catch (Exception e) {
			logger.error("修改页面异常："+e.toString());
			e.printStackTrace();
		}
	}
	/**
	 * 删除页面
	 * @param request
	 * @param response
	 * @param session
	 * @param params
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/deletePageById")
	public void deletePageById(HttpServletRequest request,HttpServletResponse response,HttpSession session,@RequestBody String params){
		
		SessionUserInfo sessionUserInfo = (SessionUserInfo) session.getAttribute(SysConstant.SESSION_KEY_LOGIN_USER);
		HashMap<String, Object> resultMap = new HashMap<String,Object>();
		if (sessionUserInfo==null) {
			resultMap.put("code", "-2");
			resultMap.put("message", "您还未登录");
		}
		HashMap<String, Object> inParam = JsonUtil.toObject(params, HashMap.class);
		String pageId = String.valueOf(inParam.get("pageId"));
		String moduleId = String.valueOf(inParam.get("moduleId"));
		try {
			PageElement pageElement = new PageElement();
			//1.删除该页面下的所有元素信息
			pageElement.setPageId(Integer.valueOf(pageId));
			elementService.deleteElement(pageElement);
			//2.查询要删除界面的父界面中元素的信息
			SharePage delPageInfo = pageService.queryPageById(Integer.valueOf(pageId));//查询该页面的信息
			PageElement pageElement2 = new PageElement();
			if (delPageInfo.getElementTargetId()!=0) {
				pageElement2.setElementId(delPageInfo.getElementTargetId());
				elementService.deleteElement(pageElement2);
			}
			//3.删除本身page
			//page对象重新生成
			SharePage pageSelf = new SharePage();
			pageSelf.setPageId(Integer.valueOf(pageId));
			pageService.deleteChildPages(pageSelf);
			//记录删除该页面的日志信息
			insertOperatorLog(sessionUserInfo.getUserId(), SysConstant.OPERATOR_ACTION_DEL_LOG, SysConstant.OPERATOR_TYPE_PAGE_LOG, Integer.valueOf(pageId), -1);
			//调用回调函数
			callBackDelPageInfo(moduleId, pageId);
			
			resultMap.put("code", "0");
			resultMap.put("message", "删除页面成功");
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/html;charset=UTF-8");
		    response.getWriter().print(JsonUtil.toString(resultMap));
		} catch (Exception e) {
			logger.error("删除页面异常："+e.toString());
			e.printStackTrace();
		}
	}
	/**
	 * 删除页面回调函数
	 * @param moduleId
	 * @param pageId
	 */
	public void callBackDelPageInfo(String moduleId,String pageId){
		
		try {
			SharePage page = new SharePage();
			//先删除pageId页面下的子页面以及子页面对应的元素，再删除本身页面
			//1。先查询该pageId下的所有子page信息
			page.setModuleId(Integer.valueOf(moduleId));
			page.setParentPageId(Integer.valueOf(pageId));
			List<HashMap<String, Object>> childPageList = pageService.queryChildPageList(page);
			//2.删除所有子page下的所有元素信息
			for (int i = 0; i < childPageList.size(); i++) {
				HashMap<String, Object> childPage = childPageList.get(i);
				//2.1 删除该子页面下的所有元素信息
				PageElement pageElement = new PageElement();
				pageElement.setPageId(Integer.valueOf(String.valueOf(childPage.get("page_id"))));
				elementService.deleteElement(pageElement);
				//2.2.查询要删除界面的父界面中元素的信息
				SharePage delPageInfo = pageService.queryPageById(Integer.valueOf(String.valueOf(childPage.get("page_id"))));
				PageElement pageElement2 = new PageElement();
				if (delPageInfo.getElementTargetId()!=0) {
					pageElement2.setElementId(delPageInfo.getElementTargetId());
					elementService.deleteElement(pageElement2);
				}
				//2.3 删除本身page    page对象重新生成
				SharePage pageSelf = new SharePage();
				pageSelf.setPageId(Integer.valueOf(String.valueOf(childPage.get("page_id"))));
				pageService.deleteChildPages(pageSelf);
				
				//如果还存在子页面，那么继续调用回调函数
				callBackDelPageInfo(moduleId,String.valueOf(childPage.get("page_id")));
			}
			
		} catch (Exception e) {
			logger.error("删除页面异常："+e.toString());
			e.printStackTrace();
		}
	}
	/**
	 * 校验页面名称是否合法
	 * @param request
	 * @param response
	 * @param session
	 * @param params
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/checkPageName")
	public void checkPageName(HttpServletRequest request,HttpServletResponse response,HttpSession session,@RequestBody String params){
		
		/*SessionUserInfo sessionUserInfo = (SessionUserInfo) session.getAttribute(SysConstant.SESSION_KEY_LOGIN_USER);
		HashMap<String, Object> resultMap = new HashMap<String,Object>();
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		try {
			if (sessionUserInfo==null) {
				resultMap.put("code", "-2");
				resultMap.put("message", "您还未登录");
				response.getWriter().print(JsonUtil.toString(resultMap));
			}
			HashMap<String, Object> inParam = JsonUtil.toObject(params, HashMap.class);
			Page page = new Page();
			String pageId = String.valueOf(inParam.get("pageId"));
			Integer moduleId = Integer.valueOf(String.valueOf(inParam.get("moduleId")));
			String pageName = String.valueOf(inParam.get("pageName"));
			page.setParentId(Integer.valueOf(pageId));
			page.setModuleId(Integer.valueOf(String.valueOf(inParam.get("moduleId"))));
			//查询该模块下所有的页面
			List<HashMap<String, Object>> pageList = pageService.queryChildPageList(page);
			Boolean isSameName = false;
			//验证该模块下是否存在页面名称，是：不执行以下操作;否：执行以下操作
			for (Iterator iterator = pageList.iterator(); iterator.hasNext();) {
				HashMap<String, Object> hashMap = (HashMap<String, Object>) iterator.next();
				if (pageName.equals(String.valueOf(hashMap.get("page_name")))) {
					isSameName = true;
					break;
				}
			}
			//若原模块中不存在此页面名称，则查询本项目中其他模块中是否存在该界面名称
			Boolean isAllTheSame = false;
			HashMap<String, Object> samePageMap = new HashMap<String,Object>();
			if (!isSameName) {
				//1.查询该项目的Id
				Module module = moduleService.queryModuleById(moduleId);
				Integer ciProjectId = module.getCiProjectId();
				//2.查询该项目下所有的模块，并排除当前模块
				List<Module> moduleLists = moduleService.queryModulesByProjectId(ciProjectId);
				for (Iterator iterator = moduleLists.iterator(); iterator.hasNext();) {
					Module moduleList = (Module) iterator.next();
					if (moduleList.getModuleId()!=moduleId) {
						//查询各个模块下是否存在这个页面名称
						Page page2 = new Page();
						page2.setModuleId(moduleList.getModuleId());
						List<HashMap<String, Object>> modulePageLists = pageService.queryChildPageList(page2);
						for (Iterator iterator2 = modulePageLists.iterator(); iterator2.hasNext();) {
							HashMap<String, Object> hashMap = (HashMap<String, Object>) iterator2.next();
							if (pageName.equals(String.valueOf(hashMap.get("page_name")))) {
								isAllTheSame = true;
								samePageMap = hashMap;
								break;
							}
						}
					}
					if (isAllTheSame==true) {
						break;
					}
				}
			}
			resultMap.put("code", "0");
			resultMap.put("message", "查询子页面成功");
			resultMap.put("isSameName", isSameName);
			resultMap.put("isAllTheSame", isAllTheSame);
			resultMap.put("samePageMap", samePageMap);
		    response.getWriter().print(JsonUtil.toString(resultMap));
		} catch (Exception e) {
			logger.error("查询子页面异常："+e.toString());
			e.printStackTrace();
		}*/
		SessionUserInfo sessionUserInfo = (SessionUserInfo) session.getAttribute(SysConstant.SESSION_KEY_LOGIN_USER);
		HashMap<String, Object> resultMap = new HashMap<String,Object>();
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		try {
			if (sessionUserInfo==null) {
				resultMap.put("code", "-2");
				resultMap.put("message", "您还未登录");
				response.getWriter().print(JsonUtil.toString(resultMap));
			}
			HashMap<String, Object> inParam = JsonUtil.toObject(params, HashMap.class);
			SharePage page = new SharePage();
			String pageId = String.valueOf(inParam.get("pageId"));
			page.setParentPageId(Integer.valueOf(pageId));
			page.setModuleId(Integer.valueOf(String.valueOf(inParam.get("moduleId"))));
			List<HashMap<String, Object>> pageList = pageService.queryChildPageList(page);
			resultMap.put("code", "0");
			resultMap.put("message", "查询子页面成功");
			resultMap.put("pageList", pageList);
		    response.getWriter().print(JsonUtil.toString(resultMap));
		} catch (Exception e) {
			logger.error("查询子页面异常："+e.toString());
			e.printStackTrace();
		}
	}
	/**
	 * 校验页面名称是否合法
	 * @param request
	 * @param response
	 * @param session
	 * @param params
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/checkModifyPageName")
	public void checkModifyPageName(HttpServletRequest request,HttpServletResponse response,HttpSession session,@RequestBody String params){
		
		SessionUserInfo sessionUserInfo = (SessionUserInfo) session.getAttribute(SysConstant.SESSION_KEY_LOGIN_USER);
		HashMap<String, Object> resultMap = new HashMap<String,Object>();
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		try {
			if (sessionUserInfo==null) {
				resultMap.put("code", "-2");
				resultMap.put("message", "您还未登录");
				response.getWriter().print(JsonUtil.toString(resultMap));
			}
			HashMap<String, Object> inParam = JsonUtil.toObject(params, HashMap.class);
			SharePage page = new SharePage();
			String pageId = String.valueOf(inParam.get("pageId"));
			page.setPageId(Integer.valueOf(pageId));
			page.setModuleId(Integer.valueOf(String.valueOf(inParam.get("moduleId"))));
			//查询本身页面的父页面id
			HashMap<String, Object> pageMap = pageService.queryPageInfo(page);
			Integer parentId = Integer.valueOf(String.valueOf(pageMap.get("parent_page_id")));
			SharePage page1 = new SharePage();
			page1.setParentPageId(parentId);
			page1.setModuleId(Integer.valueOf(String.valueOf(inParam.get("moduleId"))));
			List<HashMap<String, Object>> pageList = pageService.queryChildPageList(page1);
			resultMap.put("code", "0");
			resultMap.put("message", "查询子页面成功");
			resultMap.put("pageList", pageList);
		    response.getWriter().print(JsonUtil.toString(resultMap));
		} catch (Exception e) {
			logger.error("查询子页面异常："+e.toString());
			e.printStackTrace();
		}
	}
	
	/**
	 * 拖拽页面操作
	 * @param request
	 * @param response
	 * @param session
	 * @param params
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/dragPage")
	public void dragPage(HttpServletRequest request,HttpServletResponse response,HttpSession session,@RequestBody String params){
		
		SessionUserInfo sessionUserInfo = (SessionUserInfo) session.getAttribute(SysConstant.SESSION_KEY_LOGIN_USER);
		HashMap<String, Object> resultMap = new HashMap<String,Object>();
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		try {
			if (sessionUserInfo==null) {
				resultMap.put("code", "-2");
				resultMap.put("message", "您还未登录");
				response.getWriter().print(JsonUtil.toString(resultMap));
			}
			HashMap<String, Object> inParam = JsonUtil.toObject(params, HashMap.class);
			//处理拖拽事务
			pageService.handleDragPage(inParam);
			resultMap.put("code", "0");
			resultMap.put("message", "拖拽页面成功");
		    response.getWriter().print(JsonUtil.toString(resultMap));
		} catch (Exception e) {
			logger.error("查询子页面异常："+e.toString());
			//e.printStackTrace();
			resultMap.put("code", "-1");
			resultMap.put("message", "拖拽页面失败");
		    try {
				response.getWriter().print(JsonUtil.toString(resultMap));
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} 
	}
	
}
